package com.cjm.task3.controller;

import com.cjm.task3.dao.RegionStats;
import com.cjm.task3.service.GetDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;
import java.util.List;

@RestController
@Controller
public class GetDataController {
    @Autowired
    GetDataService service = new GetDataService();

    @RequestMapping("/test")
    public ModelAndView test(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("test");
        return modelAndView;
    }

    @RequestMapping (value = "/showData")
    public ModelAndView showData() throws IOException {
        ModelAndView modelAndView = new ModelAndView();
        List<RegionStats> data = service.getData();
        modelAndView.addObject("data", data);
        modelAndView.setViewName("showData");
        return modelAndView;
    }
}
